<?php

namespace Admin\Controller;

use Think\Model;

/**
 * Description of SpMembercardController
 *
 * @author Myron
 */
class SpMembercardController extends AdminController {

    /**
     * 展示会员卡列表
     * @author 曹梦龙 <138888611@qq.com>
     */
    function index() {
        $type=I('type');
        $name = I('name');
        switch($type){
            case 'cardnumber':
                 $map['cardNum'] = array('like', '%' . (string) $name . '%');
                break;
            case 'name':
                 $map['name'] = array('like', '%' . (string) $name . '%');
                break;
            case 'phone':
                 $map['phone'] = array('like', '%' . (string) $name . '%');
                break;
        };
        $list = $this->lists('sp_membercard', $map);
        int_to_string($list);
        $this->assign('_list', $list);
        $this->assign('type',$type);
        $this->meta_title = '会员卡列表';
        $this->display();
    }

    
    /**
     * 状态修改
     * @author 曹梦龙 <138888611@qq.com>
     */
    public function detail($id=''){
        $MembercardData= M('sp_membercard')->where(array('id'=>$id))->find();
        $map['membercardId']=$id;
        $list = $this->lists('sp_membercarddetail', $map);
        int_to_string($list);
        $this->assign('_list', $list); //会员卡使用流水
        $this->assign('data',$MembercardData);
        $this->display();
    }
    
    /**
     * 状态修改
     * @author 曹梦龙 <138888611@qq.com>
     */
    public function changeStatus($method = null, $id) {
        $id = is_array($id) ? implode(',', $id) : $id;
        if (empty($id)) {
            $this->error('请选择要操作的数据!');
        }
        $map['id'] = array('in', $id);
        switch (strtolower($method)) {
            case 'forbid':
                $this->forbid('sp_membercard', $map);
                break;
            case 'resume':
                $this->resume('sp_membercard', $map);
                break;
            case 'delete':
                $this->delete('sp_membercard', $map);
                break;
            default:
                $this->error('sp_membercard');
        }
    }

}
